< previous page page_35 next page >

Page 35
Table 2.3 Prefixes Used in a Common Variable Naming Convention
PrefixVariable Type
sString
nInteger
lLong Integer
fSingle-precision Floating Point
dDouble-precision Floating Point
cCurrency
bBoolean (True/False)
vVariant

Add the following line of code for the next declaration:
    Dim fIntRate As Single
This would be a good time to point out that multiple variables can be declared on the same line of code. If you do so, each variable must have its own type listed. Add the following line of code to declare two more variables:
    Dim nTerm As Integer, cPayment As Currency
CAUTION
A common beginner mistake is to attempt to include multiple variable declarations in a statement like Dim x, y, z As Integer. Remember, however, that each variable must have its type explicitly mentioned. In this case, only z would be an Integer; x and y would be initialized as Variants. The Variant data type is a special type discussed later in the book. The correct syntax would be to place the words As Integer after each variable name.

Procedure Code
The procedure code is the remaining part of the procedure that does the actual work. In your Loan Calculator program, this part of the procedure will be responsible for retrieving the input values from the first three text boxes, calculating the monthly payment, and displaying the payment in the fourth text box.
Enter the following two lines into the Code window (after the variable declaration statements):
    'Store the principal in the variable cPrincipal
    cPrincipal = Val(txtPrincipal.Text)
The first line is a comment explaining what's going on. A comment is denoted by a single quotation mark ('), usually at the beginning of a line. When Visual Basic encounters a single quote on a line, the remainder of the line is ignored. Visual Basic then looks to the next line for the next instruction.

 
< previous page page_35 next page >